using System;
using System.Collections.Generic;
using NHibernate.Expression;

namespace CosyTrade.StoreManagement.UI.Controls
{
    public partial class ProductSelectControl : DevExpress.XtraEditors.XtraUserControl
    {
        public ProductSelectControl()
        {
            InitializeComponent();
        }

        private IList<ExportBillItem> exportBillItems;
        private readonly Dictionary<Guid,BillState> billStates = new Dictionary<Guid, BillState>();
        private IProductManager productManager;
        private readonly IList<Product> productlst = new List<Product>();

        public IList<ExportBillItem> ExportBillItems
        {
            get 
            { 

                return exportBillItems; 
            }
            set { exportBillItems = value; }
        }

        public Dictionary<Guid, BillState> BillStates
        {
            get { return billStates; }
        }

        public IProductManager productMgr
        {
            get { return productManager; }
            set { productManager = value; }
        }

        public void Initialize()
        {
            if(exportBillItems==null) exportBillItems = new List<ExportBillItem>();
            selectsources.DataSource = exportBillItems;

            IList<Product> products = productManager.GetProductList(null, 1, 100, new Order[] { Order.Desc("CaptionChinese") });
            if (products != null)
                productSource.DataSource = products;

        }

        private void productSource_PositionChanged(object sender, EventArgs e)
        {
            
        }

        private void selectsources_PositionChanged(object sender, EventArgs e)
        {

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            
        }

        private void gridproduct_Click(object sender, EventArgs e)
        {
            Product product = productSource.Current as Product;
            if (product == null) return;
            if (!productlst.Contains(product))
                productlst.Add(product);
            else
                productlst.Remove(product);
        }
    }
}
